<?php

//init language
if (!function_exists('_')) {

    function _($string, $data = null) {
        if (!isset($GLOBALS['i18n'])) {
            $c = strtolower(C('DEFAULT_LANG'));
            if (strlen($c) < 1)
                $c = 'zh_cn';

            $lang_file = AROOT . 'local' . DS . basename($c) . '.lang.php';
            if (file_exists($lang_file)) {
                include_once( $lang_file );
                $GLOBALS['i18n'] = $c;
            } else
                $GLOBALS['i18n'] = 'zh_cn';
        }
        //print_r( $GLOBALS['language'][$GLOBALS['i18n']] );
        if (isset($GLOBALS['language'][$GLOBALS['i18n']][$string]))
            $to = $GLOBALS['language'][$GLOBALS['i18n']][$string];
        else
            $to = $string;

        if ($data == null)
            return $to;
        else {
            if (!is_array($data))
                $data = array($data);
            return vsprintf($to, $data);
        }
    }

} 	



